package com.t.testcontentprovider;


import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //insert();
        query();
        update("2333","8888");
        query();
    }

    private static final int MATCH_FIRST = 1;
    public static final String AUTHORITY = "com.t.testsql.Testprovider";
    public static final Uri CONTENT_URI_FIRST = Uri.parse("content://" + AUTHORITY + "/my_table");

    public void insert() {
        ContentValues contentValues = new ContentValues();
        contentValues.put("name","6667");
        contentValues.put("phone","6667");
        contentValues.put("age","6667");
        getContentResolver().insert(CONTENT_URI_FIRST,contentValues);
    }

    public void  update(String traget, String origin) {
        ContentValues values = new ContentValues();
        values.put("name",traget);
        getContentResolver().update(CONTENT_URI_FIRST, values,
                "name=?", new String[]{origin});
    }


    public void query() {
        Cursor cursor = this.getContentResolver().query(CONTENT_URI_FIRST, null, null, null, null);
        cursor.moveToFirst();
        while (cursor.moveToNext()) {
            String age = cursor.getString(cursor.getColumnIndex("age"));
            String name = cursor.getString(cursor.getColumnIndex("name"));
            String phone = cursor.getString(cursor.getColumnIndex("phone"));
            Log.e("test", "age" + age);
            Log.e("test ", "name: " + name);
            Log.e("test ", "phone " + phone);
        }
        cursor.close();


    }
}
